Public Class HoldingOCCReport
    Inherits [lib].BasePage

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
    Protected WithEvents ContentPaneFooter1 As Library.WebControls.ContentPaneFooter

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.PageTitle = "Holding OCC Report"

        If Not Me.IsPostBack Then
            Me.generateReport(0)
        End If
    End Sub

    Private Sub generateReport(ByVal pageIndex As Integer)
        ' BSCS_6 Version (Old)
        ' Dim query As String = "select /*+ ordered use_nl(a b cc) parallel(a 4)*/ " & _
        '                         "a.custcode, cc.ccname CompanyName, cc.ccfname || ' ' || cc.cclname ContactName, remark, USERNAME, AMOUNT, ENTDATE, VALID_FROM, PERIOD " & _
        '                         "from customer_all a, fees b, ccontact_all cc " & _
        '                         "where a.cslevel = '10' " & _
        '                         "and a.customer_id = b.customer_id  " & _
        '                         "and b.period > 0 " & _
        '                         "and cc.customer_id = b.customer_id and ccbill = 'X' " & _
        '                         "and a.billcycle < '50'"
        ' Begin : BSCS_IX_R3 Version (New)
        Dim query As String = "select /*+ ordered use_nl(a b cc) parallel(a 4)*/ " & _
                         "a.custcode, cc.ccname CompanyName, cc.ccfname || ' ' || cc.cclname ContactName, remark, USERNAME, AMOUNT, ENTDATE, VALID_FROM, PERIOD " & _
                         "from customer_all a, fees b, ccontact_all cc " & _
                         "where a.cslevel = '10' " & _
                         "and a.customer_id = b.customer_id  " & _
                         "and b.period > 0 " & _
                         "and cc.customer_id = b.customer_id and ccbill = 'X' " & _
                                "and eu_bill.fn_util_getbillcycle(a.customer_id) < '50'"
        ' End : BSCS_IX_R3 Version (New)
        Me.DataGrid1.CurrentPageIndex = pageIndex
        Me.DataGrid1.DataSource = persistent.myDBConn.myORATable(query)
        Me.DataGrid1.DataBind()
    End Sub

    Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
        Me.generateReport(e.NewPageIndex)
    End Sub

    Private Sub ContentPaneFooter1_Confirmed(ByVal sender As Object, ByVal e As System.EventArgs) Handles ContentPaneFooter1.Confirmed
        Dim currentPageIndex = Me.DataGrid1.CurrentPageIndex
        Me.DataGrid1.AllowPaging = False
        Me.generateReport(0)

        Response.Cache.SetCacheability(HttpCacheability.NoCache)

        Response.ContentType = "application/vnd.ms-excel"

        Response.Charset = ""

        Me.EnableViewState = False

        Dim stringWrite As New System.IO.StringWriter

        Dim htmlWrite As New HtmlTextWriter(stringWrite)

        Me.DataGrid1.RenderControl(htmlWrite)

        Response.Write(stringWrite.ToString())

        Response.End()
        Me.DataGrid1.AllowPaging = True
        Me.generateReport(currentPageIndex)

    End Sub
End Class

